// 个人中心页加载文章列表数据
const db =require("../lib/db")

function myArticleList(){   
    return new Promise((resolve,reject)=>{
        let sql="select * from article";
        db.querySql(sql).then(data=>{
            if(data.length==0){
                //返回状态码
                resolve(404)
            }else{
                //对数组做一个乱序处理
                let arr =data.sort(()=>0.5 - Math.random())
                let arr2=[]
                arr.map(element=>{
                    arr2.push({
                        _id: Buffer.from(String(element._id)).toString("Base64"),
                        title: element.title,
                        content: element.content,
                        descs: element.descs,
                        author: element.author,
                        authorId: element.authorId,
                        classify: element.classify,
                    })
                })
                resolve(arr2)
                console.log(arr2)
            }
        })       
    })
}

//导出
module.exports = myArticleList